package com.controller;

import java.io.IOException;

import java.io.PrintWriter;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@WebServlet("/area")
public class area extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
				this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			req.setCharacterEncoding("utf-8");
			resp.setContentType("text/html;charset=utf-8");
			String Up = req.getParameter("up");
			String Down = req.getParameter("down");
			String Height = req.getParameter("height");
			PrintWriter out = resp.getWriter();
			double result = 0.0;
			try {
result = (Double.parseDouble(Up)+Double.parseDouble(Down))*Double.parseDouble(Height)*0.5;
out.println("<html><body bgcolor='pink'>计算的结果为:"+result+"</body></html>");
			}catch(Exception e) {
out.println("<html><body bgcolor='orange'>数据输入错误,请重新输入!</body></html>");
			}
	}	
}
